using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.Model;
using MicroMsg.UI.Page;
using Microsoft.Phone.Controls;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class ForwardListItem : UserControl, MMItemCtrl, BaseHeadImgItem, ContactItemInterface
	{
		private const string TAG = "ForwardListItem";
		private const int TYPE_NORMAL = 0;
		private const int TYPE_UNREAD_VOICE = 1;
		private static ItemFlyInAndOutAnimations _flyOutAnimation;
		public static DependencyProperty ListItemProperty;
		private static Brush[] infoBrush;
		private MMHubTileImg tileImg;
		private long ShowTimer = -1L;
		private string currentImgUsername;
		public bool isLocked = true;
		private bool isHeadImgVisible;
		internal ClickEffectGrid SessionItemView;
		internal Border ImgBorder;
		internal Image HeadImg;
		internal StackPanel TitleArea;
		internal EmojiText TitleTxt;
		internal TextBlock PeopleNum;
		internal EmojiText InfoPre;
		internal SmileyText InfoContent;
		internal TextBlock TimeTxt;
		internal Border UnreadArea;
		internal TextBlock UnreadTxt;
		internal StackPanel ForwardHeadView;
		internal ClickableLayout btnNewSession;
		internal Border ImgBackGround;
		internal Image ImgHead;
		internal TextBlock txBkTitle;
		private bool _contentLoaded;
		public event ListItemClick ItemClick;
		public Conversation ItemObject
		{
			get
			{
				return (Conversation)base.GetValue(ForwardListItem.ListItemProperty);
			}
			set
			{
				base.SetValue(ForwardListItem.ListItemProperty, value);
			}
		}
		public bool IsNeedOnlyShowVisibleItem
		{
			get
			{
				return MainPage.mainPageInstance != null && MainPage.mainPageInstance.IsNeedOnlyShowVisibleItem;
			}
		}
		public string UserName
		{
			get
			{
				return this.currentImgUsername;
			}
			set
			{
				this.currentImgUsername = value;
			}
		}
		public void Refresh()
		{
			this.RefreshItem(this.ItemObject);
		}
		public ForwardListItem()
		{
			base.SetValue(TiltEffect.IsTiltEnabledProperty, true);
			base.add_Loaded(new RoutedEventHandler(this.ForwardListItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ForwardListItem_Unloaded));
			this.InitializeComponent();
			ShowObjectInMemory.AddOneObjectRecord(this);
			this.ImgBorder.set_Background(R.theme.COMMON_BRUSH);
		}
		~ForwardListItem()
		{
			ShowObjectInMemory.RemoveOneObjectRecord(this);
		}
		private void ForwardListItem_Unloaded(object sender, RoutedEventArgs e)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			if (MainPage.mainPageInstance.mHeadImgLoadService == null)
			{
				return;
			}
			MainPage.mainPageInstance.mHeadImgLoadService.Delete(this);
			MainPage.mainPageInstance.mContactUpdatedService.Delete(this);
		}
		private void ForwardListItem_Loaded(object sender, RoutedEventArgs e)
		{
			if (MainPage.mainPageInstance == null)
			{
				return;
			}
			if (MainPage.mainPageInstance.mHeadImgLoadService == null)
			{
				return;
			}
			MainPage rootPage = this.GetRootPage<MainPage>();
			if (rootPage != null)
			{
				rootPage.DoNewSync();
				rootPage.UnLockSessionItem();
			}
			MainPage.mainPageInstance.mHeadImgLoadService.Add(this);
			MainPage.mainPageInstance.mContactUpdatedService.Add(this);
			this.UnLockItem();
			this.RefreshTimerTxt();
		}
		private void Button_Click(object sender, object object_0)
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.ItemObject);
			}
		}
		static ForwardListItem()
		{
			ForwardListItem._flyOutAnimation = new ItemFlyInAndOutAnimations();
			ForwardListItem.infoBrush = new Brush[]
			{
				R.theme.LISTA_SIGNATURE_WORD_BRUSH,
				R.theme.LISTA_SIGNATURE_UNREAD_WORD_BRUSH
			};
			ForwardListItem.ListItemProperty = DependencyProperty.Register("ItemObject", typeof(Conversation), typeof(ForwardListItem), new PropertyMetadata(null, new PropertyChangedCallback(ForwardListItem.OnItemPropertyChanged)));
		}
		private void DumpConversation(Conversation conversation_0)
		{
			if (conversation_0 == null)
			{
				Log.smethod_5(base.GetType().get_Name(), "null");
				return;
			}
			Log.smethod_5(base.GetType().get_Name(), conversation_0.strUsrName);
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == ForwardListItem.ListItemProperty)
			{
				(dependencyObject_0 as ForwardListItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as Conversation);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshItem(Conversation item)
		{
			if (item == null)
			{
				return;
			}
			if (ForwardPage.FORWARD_HEAD_CONVERSION.strUsrName == item.strUsrName)
			{
				this.ForwardHeadView.set_Visibility(0);
				this.SessionItemView.set_Visibility(1);
				return;
			}
			this.ForwardHeadView.set_Visibility(1);
			this.SessionItemView.set_Visibility(0);
			if (GuideHeadSetMgr.IsSetHeadHintConv(item))
			{
				this.RefreshSetHeadItem(item);
				return;
			}
			if (BindHintManager.IsBindHintConv(item))
			{
				this.RefreshBindingItem(item);
				return;
			}
			new ImageSourceConverter();
			this.UserName = item.strUsrName;
			this.RefreshHeadImg();
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			object arg_9C_0 = phoneApplicationFrame.get_Content();
			if (ContactMgr.getUserType(item.strUsrName) == ContactMgr.UserType.UserTypeChatRoom)
			{
				int num = 0;
				this.TitleTxt.Text = ContactHelper.getChatRoomStringInSession(item.strUsrName, ref num);
				this.PeopleNum.set_Text("(" + num + ")");
			}
			else
			{
				if (item.strUsrName == "floatbottle")
				{
					this.TitleTxt.Text = strings.Float_Botlle_My_Bottle;
					this.PeopleNum.set_Text("");
				}
				else
				{
					if (item.strUsrName == "newsapp")
					{
						this.TitleTxt.Text = strings.Plugin_news_title;
						this.PeopleNum.set_Text("");
					}
					else
					{
						if (item.strUsrName == ConstantValue.TAG_BLOGAPP)
						{
							this.TitleTxt.Text = strings.Contacts_Plugin_Blog;
							this.PeopleNum.set_Text("");
						}
						else
						{
							this.TitleTxt.Text = ContactHelper.getDisplayName(item.strUsrName, null);
							this.PeopleNum.set_Text("");
						}
					}
				}
			}
			this.TimeTxt.set_Text(Util.formatTimeInList(item.nTime, true));
			this.ShowTimer = item.nTime;
			this.InfoContent.Text = "";
			this.InfoPre.Text = "";
			if (this.getInfoShowColorType(item) == 0)
			{
				string text = "";
				string text2 = MsgInfoObject.parseMsgContentToShow(item, ref text);
				if (text != null)
				{
					text2 = text + text2;
				}
				this.InfoContent.Text = text2;
				Binding binding = new Binding("LISTA_SIGNATURE_WORD_BRUSH");
				binding.set_Source(R.theme);
				this.InfoContent.SetBinding(SmileyText.ForegroundProperty, binding);
			}
			else
			{
				string text3 = "";
				string text4 = MsgInfoObject.parseMsgContentToShow(item, ref text3);
				if (string.IsNullOrEmpty(text3))
				{
					if (!string.IsNullOrEmpty(text4))
					{
						this.InfoContent.Text = text4;
						Binding binding2 = new Binding("COMMON_BRUSH");
						binding2.set_Source(R.theme);
						this.InfoContent.SetBinding(SmileyText.ForegroundProperty, binding2);
					}
				}
				else
				{
					this.InfoPre.Text = text3;
					Binding binding3 = new Binding("LISTA_SIGNATURE_WORD_BRUSH");
					binding3.set_Source(R.theme);
					this.InfoPre.SetBinding(EmojiText.ForegroundProperty, binding3);
					if (!string.IsNullOrEmpty(text4))
					{
						this.InfoContent.Text = text4;
						Binding binding4 = new Binding("COMMON_BRUSH");
						binding4.set_Source(R.theme);
						this.InfoContent.SetBinding(SmileyText.ForegroundProperty, binding4);
					}
					if (this.InfoPre.get_ActualWidth() == 0.0)
					{
						this.InfoPre.InvalidateMeasure();
					}
					this.InfoContent.set_MaxWidth(Math.Max(0.0, 245.0 - this.InfoPre.get_ActualWidth()));
				}
			}
			if (item.nUnReadCount > 0)
			{
				if (item.nUnReadCount >= 100)
				{
					this.UnreadTxt.set_Text("...");
				}
				else
				{
					this.UnreadTxt.set_Text(string.Concat(item.nUnReadCount));
				}
				this.UnreadArea.set_Visibility(0);
				return;
			}
			this.UnreadArea.set_Visibility(1);
		}
		private void GetTwoStr(string strContent, ref string str1, ref string str2)
		{
			str1 = "";
			str2 = null;
			if (string.IsNullOrEmpty(strContent))
			{
				return;
			}
			int num = strContent.IndexOf(":");
			if (num >= 0)
			{
				str1 = strContent.Substring(0, num + 1);
				if (strContent.get_Length() > num + 1)
				{
					str2 = strContent.Substring(num + 1, strContent.get_Length() - num - 1);
					return;
				}
			}
			else
			{
				str1 = strContent;
			}
		}
		public void RefreshTimerTxt()
		{
			if (this.ShowTimer < 0L)
			{
				return;
			}
			this.TimeTxt.set_Text(Util.formatTimeInList(this.ShowTimer, true));
		}
		private int getInfoShowColorType(Conversation item)
		{
			if (item == null)
			{
				return 0;
			}
			int msgType = MsgInfoObject.getMsgType(item.strMsgType);
			int result = 0;
			if (item.nIsSend == 0)
			{
				result = 0;
				if (msgType == 34 && item.nStatus == 0)
				{
					result = 1;
				}
			}
			return result;
		}
		private void RefreshBindingItem(Conversation item)
		{
			this.TimeTxt.set_Text("");
			this.InfoContent.Text = "";
			this.TitleTxt.set_MaxWidth(300.0);
			this.TitleTxt.Text = BindHintManager.GetBindTitle(item);
			this.InfoPre.Text = BindHintManager.GetBindInfo(item);
			Binding binding = new Binding("LISTA_SIGNATURE_WORD_BRUSH");
			binding.set_Source(R.theme);
			this.InfoPre.SetBinding(EmojiText.ForegroundProperty, binding);
			ImageSource bindHead = BindHintManager.GetBindHead(item);
			if (bindHead != this.HeadImg.get_Source())
			{
				this.HeadImg.set_Source(bindHead);
			}
		}
		private void RefreshSetHeadItem(Conversation item)
		{
			this.TimeTxt.set_Text("");
			this.InfoContent.Text = "";
			this.TitleTxt.Text = GuideHeadSetMgr.GetHintTitle(item);
			this.InfoPre.Text = GuideHeadSetMgr.GetHintInfo(item);
			Binding binding = new Binding("LISTA_SIGNATURE_WORD_BRUSH");
			binding.set_Source(R.theme);
			this.InfoPre.SetBinding(EmojiText.ForegroundProperty, binding);
			ImageSource bindHead = GuideHeadSetMgr.GetBindHead(item);
			if (bindHead != this.HeadImg.get_Source())
			{
				this.HeadImg.set_Source(bindHead);
			}
		}
		private void SetTileImg()
		{
		}
		public void RefreshHeadImg()
		{
			if (string.IsNullOrEmpty(this.currentImgUsername))
			{
				return;
			}
			if (this.IsNeedOnlyShowVisibleItem)
			{
				if (!this.isHeadImgVisible)
				{
					return;
				}
				this.isLocked = false;
				ImageSource headImage = HeadImgMgr.getHeadImage(this.currentImgUsername, false);
				if (headImage != this.HeadImg.get_Source())
				{
					this.HeadImg.set_Source(headImage);
					return;
				}
			}
			else
			{
				this.isLocked = false;
				ImageSource headImage2 = HeadImgMgr.getHeadImage(this.currentImgUsername, false);
				if (headImage2 != this.HeadImg.get_Source())
				{
					this.HeadImg.set_Source(headImage2);
				}
			}
		}
		public void HeadImgLoaded()
		{
			this.isHeadImgVisible = true;
			this.RefreshHeadImg();
		}
		public void UnLockItem()
		{
			if (!this.isLocked)
			{
				return;
			}
			this.isLocked = false;
			this.RefreshHeadImg();
		}
		public void SetVisible()
		{
			if (this.isHeadImgVisible)
			{
				return;
			}
			this.isHeadImgVisible = true;
			this.RefreshHeadImg();
		}
		public void ScreenIn()
		{
		}
		public void ScreenOut()
		{
		}
		public void ContactDataUpdated()
		{
			this.RefreshItem(this.ItemObject);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/forward/ForwardListItem.xaml", 2));
			this.SessionItemView = (ClickEffectGrid)base.FindName("SessionItemView");
			this.ImgBorder = (Border)base.FindName("ImgBorder");
			this.HeadImg = (Image)base.FindName("HeadImg");
			this.TitleArea = (StackPanel)base.FindName("TitleArea");
			this.TitleTxt = (EmojiText)base.FindName("TitleTxt");
			this.PeopleNum = (TextBlock)base.FindName("PeopleNum");
			this.InfoPre = (EmojiText)base.FindName("InfoPre");
			this.InfoContent = (SmileyText)base.FindName("InfoContent");
			this.TimeTxt = (TextBlock)base.FindName("TimeTxt");
			this.UnreadArea = (Border)base.FindName("UnreadArea");
			this.UnreadTxt = (TextBlock)base.FindName("UnreadTxt");
			this.ForwardHeadView = (StackPanel)base.FindName("ForwardHeadView");
			this.btnNewSession = (ClickableLayout)base.FindName("btnNewSession");
			this.ImgBackGround = (Border)base.FindName("ImgBackGround");
			this.ImgHead = (Image)base.FindName("ImgHead");
			this.txBkTitle = (TextBlock)base.FindName("txBkTitle");
		}
	}
}
